from config import HOST


class ApiRegisterLogin:
    """
        目标：注册登录模块 接口封装
    """

    def __init__(self, session):
        self.session = session
        # 被封装url
        self.__url_img_code = HOST + "/common/public/verifycode1/{}"
        self.__url_phone_code = HOST + "/member/public/sendSms"
        self.__url_register = HOST + "/member/public/reg"
        self.__url_login = HOST + "/member/public/login"
        self.__url_login_status = HOST + "/member/public/islogin"

    # 1、获取图片验证码接口 封装
    def api_img_code(self, random):
        return self.session.get(url=self.__url_img_code.format(random))

    # 2、获取短信验证码接口 封装
    def api_phone_code(self, phone, imgVerifyCode):
        # 定义参数
        data = {
            "phone": phone,
            "imgVerifyCode": imgVerifyCode,
            "type": "reg"
        }
        # 调用post方法
        return self.session.post(url=self.__url_phone_code, data=data)

    # 3、注册接口 封装
    def api_register(self, phone, password, verifycode, phone_code):
        # 定义参数
        data = {
            "phone": phone,
            "password": password,
            "verifycode": verifycode,
            "phone_code": phone_code,
            "dy_server": "on",
            "invite_phone": ""
        }
        # 调用post方法
        return self.session.post(url=self.__url_register, data=data)

    # 4、登录接口 封装
    def api_login(self, keywords="13600001111", password="test123"):
        # 定义参数
        data = {
            "keywords": keywords,
            "password": password
        }
        # 调用post方法
        return self.session.post(url=self.__url_login, data=data)

    # 5、查询登录接口 封装
    def api_login_status(self):
        return self.session.post(url=self.__url_login_status)

